package com.ruoyi.system.WebController;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.text.Convert;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.ByDb15;
import com.ruoyi.system.domain.ByShopcar;
import com.ruoyi.system.service.IByMyStandardService;
import com.ruoyi.system.service.IByShopcarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.repository.query.Param;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;


/**
 * StandardController
 *
 * @author ruoyi
 * @date 2024-02-01
 */
@RestController
@RequestMapping("/byWeb/shopcar")
public class WebByShopCarController extends BaseController {

    @Autowired
    private IByShopcarService byShopcarService;

    @Autowired
    private IByMyStandardService byMyStandardService;

    /**
     * 查询ByShopCar列表
     */
    @GetMapping("/list")
    public TableDataInfo list(ByShopcar byShopcar)
    {
        startPage();
        List<ByShopcar> list = byShopcarService.selectByShopcarList(byShopcar);
        return getDataTable(list);
    }

    /**
     * 查询ByShopCar列表
     */
    @GetMapping("/listUser")
    public TableDataInfo listUser(ByShopcar byShopcar)
    {
//        startPage();
        int pageSize = Convert.toInt(ServletUtils.getParameter("pageSize"));
        int pageNum = Convert.toInt(ServletUtils.getParameter("pageNum"));
        return byShopcarService.selectByShopcarUserList(SecurityUtils.getUserId(),pageNum,pageSize);
    }


    /**
     * 新增ByShopCar
     */
    @Log(title = "ByShopCar", businessType = BusinessType.INSERT)
    @PostMapping("/addCar")
    public AjaxResult add(@RequestBody ByShopcar byShopcar)
    {
        return byShopcarService.insertByShopcar(byShopcar);
    }


    /**
     * 删除ByShopCar
     */
    @Log(title = "ByShopCar", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(byShopcarService.deleteByShopcarByIds(ids));
    }


    /**
     * 结算
     */
    @Log(title = "ByShopCar", businessType = BusinessType.INSERT)
    @PostMapping("/buyStandard")
    public AjaxResult shop(@RequestBody List<ByDb15> byShopcar)
    {
        return byShopcarService.buyStandard(byShopcar);
    }


    /**
     * 判断当前standard是否购买
     */
    @Log(title = "judgeIsBuy", businessType = BusinessType.INSERT)
    @GetMapping ("/judgeIsBuy")
    public AjaxResult judgeIsBuy(@Param("standardId") String standardId)
    {
        return AjaxResult.success(byMyStandardService.judgeIsBuy(standardId));
    }

}
